package com.java8.comparator;

import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * <p>Description: [比较器]</p>
 * Created on 2020/5/25
 *
 * @author <a href="mailto: 819712047@qq.ocm">谢振东 </a>
 * @version 1.0
 */
public class ComparatorTest {
    public static void main(String[] args) {
        List<String> list = Arrays.asList("nihao", "hello", "welcome");
        System.out.println(list);
        System.out.println("----------------------------");
        Collections.sort(list, ((item1, item2) -> item2.length() - item1.length()));
        System.out.println(list);
        System.out.println("----------------------------");
        Collections.sort(list, Comparator.comparingInt(String::length).reversed());
        System.out.println(list);
        System.out.println("------------多个比较器组合------------");
        // 先按照长度排序如果长度相同，则再按照ASC码排序
        Collections.sort(list, Comparator.comparingInt(String::length).thenComparing(String.CASE_INSENSITIVE_ORDER));
        System.out.println(list);
    }
}
